from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-27 14:11:31.061899
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 27, Oct, 2022
Time: 14:11:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8347
Nobs: 822.000 HQIC: -51.1526
Log likelihood: 10697.8 FPE: 4.99741e-23
AIC: -51.3505 Det(Omega_mle): 4.48210e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.288746 0.051718 5.583 0.000
L1.Burgenland 0.109241 0.035130 3.110 0.002
L1.Kärnten -0.106770 0.018715 -5.705 0.000
L1.Niederösterreich 0.210970 0.073520 2.870 0.004
L1.Oberösterreich 0.102557 0.070443 1.456 0.145
L1.Salzburg 0.250246 0.037388 6.693 0.000
L1.Steiermark 0.037651 0.048962 0.769 0.442
L1.Tirol 0.107652 0.039723 2.710 0.007
L1.Vorarlberg -0.057845 0.034177 -1.692 0.091
L1.Wien 0.061765 0.062857 0.983 0.326
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061442 0.106916 0.575 0.566
L1.Burgenland -0.032748 0.072624 -0.451 0.652
L1.Kärnten 0.047582 0.038690 1.230 0.219
L1.Niederösterreich -0.172992 0.151987 -1.138 0.255
L1.Oberösterreich 0.386138 0.145625 2.652 0.008
L1.Salzburg 0.286501 0.077291 3.707 0.000
L1.Steiermark 0.105057 0.101219 1.038 0.299
L1.Tirol 0.314608 0.082118 3.831 0.000
L1.Vorarlberg 0.025609 0.070654 0.362 0.717
L1.Wien -0.014676 0.129944 -0.113 0.910
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186819 0.026534 7.041 0.000
L1.Burgenland 0.090812 0.018024 5.038 0.000
L1.Kärnten -0.008499 0.009602 -0.885 0.376
L1.Niederösterreich 0.264682 0.037720 7.017 0.000
L1.Oberösterreich 0.126087 0.036141 3.489 0.000
L1.Salzburg 0.048438 0.019182 2.525 0.012
L1.Steiermark 0.017593 0.025120 0.700 0.484
L1.Tirol 0.095107 0.020380 4.667 0.000
L1.Vorarlberg 0.059588 0.017535 3.398 0.001
L1.Wien 0.120270 0.032249 3.729 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104764 0.027218 3.849 0.000
L1.Burgenland 0.045020 0.018488 2.435 0.015
L1.Kärnten -0.016410 0.009849 -1.666 0.096
L1.Niederösterreich 0.193719 0.038692 5.007 0.000
L1.Oberösterreich 0.293903 0.037072 7.928 0.000
L1.Salzburg 0.116589 0.019676 5.925 0.000
L1.Steiermark 0.099573 0.025768 3.864 0.000
L1.Tirol 0.117821 0.020905 5.636 0.000
L1.Vorarlberg 0.070915 0.017987 3.943 0.000
L1.Wien -0.026525 0.033080 -0.802 0.423
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117178 0.049476 2.368 0.018
L1.Burgenland -0.049635 0.033607 -1.477 0.140
L1.Kärnten -0.040686 0.017904 -2.272 0.023
L1.Niederösterreich 0.169543 0.070333 2.411 0.016
L1.Oberösterreich 0.137651 0.067388 2.043 0.041
L1.Salzburg 0.285729 0.035767 7.989 0.000
L1.Steiermark 0.035141 0.046840 0.750 0.453
L1.Tirol 0.167077 0.038000 4.397 0.000
L1.Vorarlberg 0.105375 0.032695 3.223 0.001
L1.Wien 0.074295 0.060132 1.236 0.217
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055230 0.039154 1.411 0.158
L1.Burgenland 0.039805 0.026596 1.497 0.134
L1.Kärnten 0.050318 0.014169 3.551 0.000
L1.Niederösterreich 0.225578 0.055659 4.053 0.000
L1.Oberösterreich 0.283517 0.053329 5.316 0.000
L1.Salzburg 0.052274 0.028305 1.847 0.065
L1.Steiermark -0.008434 0.037067 -0.228 0.820
L1.Tirol 0.151326 0.030072 5.032 0.000
L1.Vorarlberg 0.071373 0.025874 2.758 0.006
L1.Wien 0.079784 0.047587 1.677 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169025 0.046785 3.613 0.000
L1.Burgenland -0.005046 0.031780 -0.159 0.874
L1.Kärnten -0.061485 0.016930 -3.632 0.000
L1.Niederösterreich -0.082674 0.066508 -1.243 0.214
L1.Oberösterreich 0.192965 0.063724 3.028 0.002
L1.Salzburg 0.058179 0.033822 1.720 0.085
L1.Steiermark 0.229572 0.044293 5.183 0.000
L1.Tirol 0.496133 0.035934 13.807 0.000
L1.Vorarlberg 0.050450 0.030918 1.632 0.103
L1.Wien -0.045312 0.056862 -0.797 0.426
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155457 0.053643 2.898 0.004
L1.Burgenland -0.011026 0.036438 -0.303 0.762
L1.Kärnten 0.065568 0.019412 3.378 0.001
L1.Niederösterreich 0.200934 0.076256 2.635 0.008
L1.Oberösterreich -0.059317 0.073064 -0.812 0.417
L1.Salzburg 0.217634 0.038779 5.612 0.000
L1.Steiermark 0.113159 0.050785 2.228 0.026
L1.Tirol 0.078949 0.041201 1.916 0.055
L1.Vorarlberg 0.125043 0.035449 3.527 0.000
L1.Wien 0.115334 0.065197 1.769 0.077
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348817 0.031288 11.149 0.000
L1.Burgenland 0.006465 0.021253 0.304 0.761
L1.Kärnten -0.023718 0.011322 -2.095 0.036
L1.Niederösterreich 0.224467 0.044478 5.047 0.000
L1.Oberösterreich 0.174513 0.042616 4.095 0.000
L1.Salzburg 0.048217 0.022619 2.132 0.033
L1.Steiermark -0.015938 0.029621 -0.538 0.591
L1.Tirol 0.110084 0.024031 4.581 0.000
L1.Vorarlberg 0.074234 0.020676 3.590 0.000
L1.Wien 0.053861 0.038027 1.416 0.157
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041921 0.153138 0.190587 0.159810 0.126033 0.116005 0.066916 0.227647
Kärnten 0.041921 1.000000 -0.002396 0.129867 0.042427 0.096777 0.429243 -0.052713 0.101254
Niederösterreich 0.153138 -0.002396 1.000000 0.338145 0.156816 0.300894 0.112909 0.185000 0.329394
Oberösterreich 0.190587 0.129867 0.338145 1.000000 0.234201 0.333561 0.175041 0.173910 0.264365
Salzburg 0.159810 0.042427 0.156816 0.234201 1.000000 0.148039 0.131075 0.150306 0.136910
Steiermark 0.126033 0.096777 0.300894 0.333561 0.148039 1.000000 0.154971 0.142144 0.080204
Tirol 0.116005 0.429243 0.112909 0.175041 0.131075 0.154971 1.000000 0.116598 0.156905
Vorarlberg 0.066916 -0.052713 0.185000 0.173910 0.150306 0.142144 0.116598 1.000000 0.008775
Wien 0.227647 0.101254 0.329394 0.264365 0.136910 0.080204 0.156905 0.008775 1.000000